package com.zgh.interceptor;//package com.zgh.interceptor;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.Map;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.io.FileUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.xxg.base.module.Operater;
//import com.xxg.util.SystemConstant;
//import com.zgh.cache.CacheConstant;
//import com.zgh.cache.RedisCache;
//import com.zgh.common.controller.BaseController;
//
//@Controller
//public class LoginAppController extends BaseController {
//    private static final Logger logger = LoggerFactory.getLogger(LoginAppController.class);
//
//    @Autowired
//    private RedisCache redisCache;
//
//    private static final String AUTHTOKEN_KEY = CacheConstant.SSO_SERVER + ":authToken";
//
//    private Operater checkAuthToken(String authToken) {
//        if (StringUtils.isBlank(authToken)) {
//            return null;
//        }
//
//        Map<String, Object> authTokenMap = (Map<String, Object>) redisCache.getMapValue(AUTHTOKEN_KEY, authToken);
//        if (authTokenMap == null || authTokenMap.isEmpty()) {
//            return null;
//        }
//        return (Operater) authTokenMap.get("operater");
//    }
//
//    @RequestMapping(value = "/app/autoLogin")
//    public String autoLogin(HttpServletRequest request, HttpServletResponse response, Model model) {
//        //APP自动登录
//        String authToken = request.getParameter("authToken");
//        Operater operater = checkAuthToken(authToken);
//        if (operater == null) {
//            return null;
//        }
//
//        request.getSession().setAttribute(SystemConstant.SESSION_USER_KEY, operater);  //用户信息
//        model.addAttribute("fullName", operater.getFullName());
//        return "index/hello";
//    }
//
//
//    @RequestMapping(value = "/app/post1")
//    public String post1(HttpServletRequest request, HttpServletResponse response, Model model) {
//
//        return "index/post1";
//    }
//
//    //测试普通的post请求
//    @RequestMapping(value = "/app/getInfo")
//    public @ResponseBody
//    Object getInfo(int x, String y, Operater ope, HttpServletRequest request, HttpServletResponse response) {
//        System.out.println("x:" + x);
//        System.out.println("y:" + y);
//        System.out.println("operater:" + ope.getFullName());
//
//        return getAppOperater(request);
//    }
//
//    @RequestMapping(value = "/app/post2")
//    public String post2(HttpServletRequest request, HttpServletResponse response, Model model) {
//        return "index/post2";
//    }
//
//
//    //测试上传文件的post请求
//    @RequestMapping(value = "/app/postImage")
//    public @ResponseBody
//    Object postImage(int x, String y, Operater ope, MultipartFile file1, MultipartFile file2, HttpServletRequest request, HttpServletResponse response) {
//
//        System.out.println("x:" + x);
//        System.out.println("y:" + y);
//        System.out.println("operater:" + ope.getFullName());
//
//        try {
//            FileUtils.writeByteArrayToFile(new File("d:/a1.jpg"), file1.getBytes());
//            FileUtils.writeByteArrayToFile(new File("d:/a2.jpg"), file2.getBytes());
//        } catch (IOException e) {
//            return new RuntimeException("文件上传失败");
//        }
//        return getAppOperater(request);
//    }
//
//
//}
